<?php

namespace App\Http\Requests\finance;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait AgentInvoiceRequest
{
    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'agent_id' => 'required|integer|exists:t_agent,id',
            'company_name' => 'required',
            'tax_number' => 'required',
            'open_bank' => 'required',
            'bank_account' => 'required',
            'company_address' => 'required',
            'company_mobile' => 'required',
            'type' => 'required',
            'amount' => 'required',
            'cycle_start' => 'required',
            'cycle_end' => 'required',
        ], [
            'agent_id.required' => '请选择客户',
            'company_name.required' => '请填写公司名称',
            'tax_number.required' => '请填写公司税号',
            'open_bank.required' => '请填写开户行',
            'bank_account.required' => '请填写银行账号',
            'company_address.required' => '请填写公司地址',
            'company_mobile.required' => '请填写公司电话',
            'type.required' => '请选择发票类型',
            'amount.required' => '请填写发票金额',
            'cycle_start.required' => '请选择周期',
            'cycle_end.required' => '请选择周期',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
